package com.example.fruitdb;

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Objects;
import javax.servlet.http.*;
import javax.servlet.annotation.*;

@WebServlet(name = "indexServlet", value = "/index-servlet")
public class indexServlet extends HttpServlet {
    private String message;

    public void init() {
        System.out.println("Servlet is working");
        message = "Hello World!";
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("text/html;charset=UTF-8");

        // Hello
        PrintWriter out = response.getWriter();
        message = System.currentTimeMillis() + "";
        String requestURI = request.getRequestURI();
        String method = request.getMethod();
        String webName = request.getContextPath();
        out.println("<h1>" + requestURI + "</h1>");
        out.println("<h1>" + method + "</h1>");
        out.println("<h1>" + webName + "</h1>");
        out.println("<html><body>");
        out.println("<h1>" + message + "</h1>");
        out.println("</body></html>");
        System.out.println("Accept a get request");

    }

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
        doGet(request, response);
    }

    public void destroy() {
    }
}